<%@page import="br.com.maternity.classes.dao.UsuarioDAO"%>
<%@page import="br.com.maternity.classes.entity.Usuario"%>
<%@page import="br.com.maternity.classes.entity.Usuario"%>
<%@page import="br.com.maternity.classes.dao.MedicoDAO"%>
<%@page import="br.com.maternity.classes.entity.Medico"%>
<jsp:include page="../cabecalho.jsp"></jsp:include>
<%
    String id = "0";
    String crm = "";
    String nome = "";
    String cpf = "";
    String telefone = "";
    String senha = "";
    String servletUrl = request.getContextPath() + "/cadastroMedico";
    Medico m = null;
    if (request.getParameter("id") != null) {
        servletUrl += "?acao=1";
        id = request.getParameter("id").toString();
        m = new MedicoDAO().getByCrm(Integer.parseInt(id));
        if (m != null) {
            crm = m.getCrm().toString();
            nome = m.getNome();
            cpf = m.getCpf();
            telefone = m.getTelefone();
            Usuario u = new UsuarioDAO().getByLoginTipo(crm, 2);
            if (u != null) {
                senha = u.getSenha();
            }
        }
    } else {
        servletUrl += "?acao=0";
    }
%>
<div id="titulo">Cadastro de Medico</div>
<div id="erro"></div>
<form id="frmMedico" name="frmMedico" method="POST" action="cadastroMedico">
    <input type="hidden" name="hdfId" id="hdfId" value="<%=id%>">
    <table>
        <tr>
            <td>CRM: <br /> <input type="text" name="txtCRM" id="txtCRM" value="<%=crm%>" 
                                   <%
                                       if (m != null) {
                                   %>
                                   disabled="disabled"
                                   <%                            }
                                   %>
                                   ></td>
            <td>CPF: <br /> <input type="text" name="txtCPF" id="txtCPF" maxlength="11" value="<%=cpf%>"></td>
        </tr>
        <tr>
            <td>Nome: <br /> <input type="text" name="txtNome" id="txtNome" maxlength="200" value="<%=nome%>"></td>
            <td>Telefone: <br /> <input type="text" name="txtTelefone" id="txtTelefone" maxlength="12" value="<%=telefone%>"></td>
        </tr>
        <tr>
            <td>Senha: <br /> <input type="password" name="txtSenha" id="txtSenha" value="<%=senha%>"></td>
        </tr>
    </table>
    <br />
    
    <a class="botao" href="#" onclick="enviaForm('frmMedico', '<%=servletUrl%>','erro');">Salvar</a>&nbsp;&nbsp;
    <a class="botao" href="<%=request.getContextPath() + "/relatorios/listagemMedicos.jsp"%>">Voltar </a>
</form>
<jsp:include page="../rodape.jsp"></jsp:include>